import os
import threading
import time
from threading import Thread, current_thread, active_count, Lock,RLock

age = 100
# 创建锁对象，每个线程都拥有同一个锁对象
mutex = RLock()


def task():
    global age
    # 给数据加锁
    mutex.acquire()
    temp = age
    time.sleep(0.05)
    age = temp - 1
    # 给数据解锁
    mutex.release()


if __name__ == '__main__':
    li = []
    for i in range(120):
        t = Thread(target=task)
        t.start()
        li.append(t)

    for i in li:
        i.join()

    print(age)
